﻿using CTTest.Common;
using CTTest.Essential.Soap.BMS;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace CTTest.Essential
{
    class CtcUtil
    {
        public static bool TestContent(ContentMNGRequest req, WriteLogger log)
        {
            dynamic result;
            return TestContent(req, log, out result);
        }
        public static bool TestNotify(ContentMNGNotify1 req, WriteLogger log)
        {
            dynamic result;
            return TestNotify(req, log, out result);
        }
        public static bool TestInstantSubscribe(InstantSubscribeRequest req, WriteLogger log)
        {
            dynamic result;
            return TestInstantSubscribe(req, log, out result);
        }
        public static bool TestLogin(LoginReq req, WriteLogger log)
        {
            dynamic result;
            return TestLogin(req, log, out result);
        }
        public static bool TestIdentifyBusiness(CTTest.Essential.Soap.BMS.SVA.ServiceAuth1 req, WriteLogger log)
        {
            dynamic result;
            return TestIdentifyBusiness(req, log, out result);
        }
        public static bool TestGetProductInfo(CTTest.Essential.Soap.BMS.SUA.SubAuthReq req, WriteLogger log)
        {
            dynamic result;
            return TestGetProductInfo(req, log, out result);
        }
        public static bool TestChangeUser(UserChgReq req, WriteLogger log)
        {
            dynamic result;
            return TestChangeUser(req, log, out result);
        }
        public static bool TestGetUserInfo(UserQueryReq req, WriteLogger log)
        {
            dynamic result;
            return TestGetUserInfo(req, log, out result);
        }



        public static bool TestContent(ContentMNGRequest req, WriteLogger log, out dynamic result)
        {
            Assert.IsNotNull(req, "ContentMNGRequest req");
            Assert.IsNotNull(log, "WriteLogger log");

            using (ContentMNG sc = new ContentMNG())
            {
                log("Begin to invoke soap method {0}\r\n{1}", sc.Url, TestUtil.WrapperObject(req));

                var e = sc.content(req);

                log("Finish to invoke soap method {0}\r\n{1}", sc.Url, TestUtil.WrapperObject(e));
                result = e;
                return e.resultCode == 0;
            }
        }
        public static bool TestNotify(ContentMNGNotify1 req, WriteLogger log, out dynamic result)
        {
            Assert.IsNotNull(req, "ContentMNGNotify1 req");
            Assert.IsNotNull(log, "WriteLogger log");

            using (ContentMNGNotify sc = new ContentMNGNotify())
            {
                log("Begin to invoke soap method {0}\r\n{1}", sc.Url, TestUtil.WrapperObject(req));

                var e = sc.notify(req);

                log("Finish to invoke soap method {0}\r\n{1}", sc.Url, TestUtil.WrapperObject(e));
                result = e;
                return e.ResultCode == "0";
            }
        }
        public static bool TestInstantSubscribe(InstantSubscribeRequest req, WriteLogger log, out dynamic result)
        {
            Assert.IsNotNull(req, "InstantSubscribeRequest req");
            Assert.IsNotNull(log, "WriteLogger log");

            using (InstantSubscribe sc = new InstantSubscribe())
            {
                log("Begin to invoke soap method {0}\r\n{1}", sc.Url, TestUtil.WrapperObject(req));

                var e = sc.instantSubscribe(req);

                log("Finish to invoke soap method {0}\r\n{1}", sc.Url, TestUtil.WrapperObject(e));
                result = e;
                return e.Result == "0";
            }
        }
        public static bool TestLogin(LoginReq req, WriteLogger log, out dynamic result)
        {
            Assert.IsNotNull(req, "LoginReq req");
            Assert.IsNotNull(log, "WriteLogger log");

            using (Login sc = new Login())
            {
                log("Begin to invoke soap method {0}\r\n{1}", sc.Url, TestUtil.WrapperObject(req));

                var e = sc.login(req);

                log("Finish to invoke soap method {0}\r\n{1}", sc.Url, TestUtil.WrapperObject(e));
                result = e;
                return e.Result == "0";
            }
        }
        public static bool TestIdentifyBusiness(CTTest.Essential.Soap.BMS.SVA.ServiceAuth1 req, WriteLogger log, out dynamic result)
        {
            Assert.IsNotNull(req, "ServiceAuth1 req");
            Assert.IsNotNull(log, "WriteLogger log");

            using (CTTest.Essential.Soap.BMS.SVA.ServiceAuth sc =
                new CTTest.Essential.Soap.BMS.SVA.ServiceAuth())
            {
                log("Begin to invoke soap method {0}\r\n{1}", sc.Url, TestUtil.WrapperObject(req));

                var e = sc.identifyBusiness(req);

                log("Finish to invoke soap method {0}\r\n{1}", sc.Url, TestUtil.WrapperObject(e));
                result = e;
                return e.Result == "0";
            }
        }
        public static bool TestGetProductInfo(CTTest.Essential.Soap.BMS.SUA.SubAuthReq req, WriteLogger log, out dynamic result)
        {
            Assert.IsNotNull(req, "SubAuthReq req");
            Assert.IsNotNull(log, "WriteLogger log");

            using (CTTest.Essential.Soap.BMS.SUA.SubAuth sc =
                new CTTest.Essential.Soap.BMS.SUA.SubAuth())
            {
                log("Begin to invoke soap method {0}\r\n{1}", sc.Url, TestUtil.WrapperObject(req));

                var e = sc.getProductInfo(req);

                log("Finish to invoke soap method {0}\r\n{1}", sc.Url, TestUtil.WrapperObject(e));
                result = e;
                return e.ResultCode == "0";
            }
        }
        public static bool TestChangeUser(UserChgReq req, WriteLogger log, out dynamic result)
        {
            Assert.IsNotNull(req, "UserChgReq req");
            Assert.IsNotNull(log, "WriteLogger log");

            using (UserChg sc = new UserChg())
            {
                log("Begin to invoke soap method {0}\r\n{1}", sc.Url, TestUtil.WrapperObject(req));

                var e = sc.changeUser(req);

                log("Finish to invoke soap method {0}\r\n{1}", sc.Url, TestUtil.WrapperObject(e));
                result = e;
                return e.Result == "0";
            }
        }
        public static bool TestGetUserInfo(UserQueryReq req, WriteLogger log, out dynamic result)
        {
            Assert.IsNotNull(req, "UserQueryReq req");
            Assert.IsNotNull(log, "WriteLogger log");

            using (UserQuery sc = new UserQuery())
            {
                log("Begin to invoke soap method {0}\r\n{1}", sc.Url, TestUtil.WrapperObject(req));

                var e = sc.getUserInfo(req);

                log("Finish to invoke soap method {0}\r\n{1}", sc.Url, TestUtil.WrapperObject(e));
                result = e;
                return e.Result == "0";
            }
        }
    }
}
